﻿using BCCommon.Enums;
using BCData.WeChatComponent.WeChatMessageRecord;
using BCEntity.WeChatComponent.WeChatMessageRecord;
using System;
using System.Collections.Generic;
using System.Text;
using WeChatSDK.WeChatDto.Conversation.ReceivingMessage;
using WeChatSDK.WeChatDto.Conversation.ReceivingMessage.EventMessage;

namespace BCService.WeChatComponent.WeChatHandleService.EventMessageService.LocationEventMessageService
{
    /// <summary>
    /// 上报地理位置事件处理
    /// </summary>
    public class LocationEventMessageService : IWeChatMessageHandle
    {
        private readonly IWeChatMessageRecordData weChatMessageRecordData;

        public LocationEventMessageService(IWeChatMessageRecordData weChatMessageRecordData)
        {
            this.weChatMessageRecordData = weChatMessageRecordData;
        }

        public string HandleMessage(ReceivingMessageDto message)
        {
            LocationEventMessageDto locationEventMessageDto = (LocationEventMessageDto)message;
            WeChatMessageRecordEntity weChatMessageRecordEntity = this.RecordReceivingMessage(locationEventMessageDto);
            //TODO:这里可以增加事件处理-例如宝徕的扫码使用红包
            string response = "success";
            return response;
        }

        private WeChatMessageRecordEntity RecordReceivingMessage(LocationEventMessageDto locationEventMessageDto)
        {
            WeChatMessageRecordEntity entity = new WeChatMessageRecordEntity()
            {
                ToUserName = locationEventMessageDto.ToUserName,
                FromUserName = locationEventMessageDto.FromUserName,
                MessageType = WeChatMessageType.Event,
                MessageId = locationEventMessageDto.MsgId,
                EventName = locationEventMessageDto.Event,
                LocationX = locationEventMessageDto.Latitude,
                LocationY = locationEventMessageDto.Longitude,
                LocationPrecision = locationEventMessageDto.Precision,
                Title = "用户上报地理位置事件",
                IsReply = false
            };
            return this.weChatMessageRecordData.Add(entity);
        }
    }
}
